-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass DeployTarget in SDK #5616
Pass DeployTarget in SDK #5616
Conversation
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
0b6ccd7
to
fa64fcd
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5616 +/- ##
=======================================
Coverage 26.58% 26.58%
=======================================
Files 474 474
Lines 50546 50564 +18
=======================================
+ Hits 13438 13444 +6
- Misses 36045 36057 +12
Partials 1063 1063 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
I think the spec you're trying to implement is good, and I've commented on how you've implemented it.
pkg/plugin/sdk/deployment.go
Outdated
dtNames, err := request.GetInput().GetDeployment().GetDeployTargets(s.commonFields.config.Name) | ||
if err != nil { | ||
return nil, status.Errorf(codes.Internal, "failed to get deploy targets for plugin %s: %v", s.commonFields.config.Name, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugin which doesn't have deploy target configurations such as WAIT will return an error in this if statement, and it's not expected behavior.
ref;
pipecd/pkg/model/deployment.go
Lines 217 to 224 in 4afa3e6
func (d *Deployment) GetDeployTargets(pluginName string) ([]string, error) { | |
dps, ok := d.GetDeployTargetsByPlugin()[pluginName] | |
if !ok || len(dps.GetDeployTargets()) == 0 { | |
return nil, fmt.Errorf("deploy target not found for plugin %v", pluginName) | |
} | |
return dps.GetDeployTargets(), nil | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/plugin/sdk/deployment.go
Outdated
if dt := s.commonFields.config.FindDeployTarget(name); dt != nil { | ||
var sdkDt DeployTargetConfig | ||
if err := json.Unmarshal(dt.Config, &sdkDt); err != nil { | ||
return nil, status.Errorf(codes.Internal, "failed to unmarshal deploy target config: %v", err) | ||
} | ||
|
||
deployTargets = append(deployTargets, &DeployTarget[DeployTargetConfig]{ | ||
Name: name, | ||
Labels: dt.Labels, | ||
Config: sdkDt, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[IMO]
We can use the early-return pattern with the error containing the deployTarget name that is not found when dt == nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed on 8173d91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I left some nits.
pkg/plugin/sdk/deployment.go
Outdated
} | ||
|
||
if len(dtNames) != len(deployTargets) { | ||
return nil, status.Errorf(codes.Internal, "the number of deploy targets in the piped plugin config should be the same as the ones set on the deployment") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nits]
Let's add len(dtNames)
and len(deployTargets)
in the message to make it easier to troubleshoot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed on fc90b4c
pkg/plugin/sdk/deployment.go
Outdated
|
||
dtNames, err := request.GetInput().GetDeployment().GetDeployTargets(s.commonFields.config.Name) | ||
if err != nil { | ||
return nil, status.Errorf(codes.Internal, "failed to get deploy targets for plugin %s: %v", s.commonFields.config.Name, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nits]
[nit]
I wanna clarify which one we mention,
- the deployTraget was not found in a piped config
- the deployTarget was not set in the request(deployment)
return nil, status.Errorf(codes.Internal, "failed to get deploy targets for plugin %s: %v", s.commonFields.config.Name, err) | |
return nil, status.Errorf(codes.Internal, "failed to get deploy targets from the deployment for plugin %s: %v", s.commonFields.config.Name, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed on fbb133e
pkg/plugin/sdk/deployment.go
Outdated
var sdkDt DeployTargetConfig | ||
if err := json.Unmarshal(dt.Config, &sdkDt); err != nil { | ||
return nil, status.Errorf(codes.Internal, "failed to unmarshal deploy target config: %v", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[IMO] If possible, it's better to cache DeployTargetConfigs in the server instead of repeating unmarshaling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! TODO is best for this case!
We don't have to do that now.
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
…which don't need them Signed-off-by: Yoshiki Fujikane <[email protected]>
pkg/plugin/sdk/deployment.go
Outdated
for _, name := range dtNames { | ||
dt := s.commonFields.config.FindDeployTarget(name) | ||
if dt == nil { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[IMO]
How about returning an error here? If we return here, we can remove the if len(dtNames) != len(deployTargets)
block after the for loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Yoshiki Fujikane <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What this PR does:
as title
Why we need it:
We need DeployTarget for the Deployment plugin to use platform-specific config.
Which issue(s) this PR fixes:
Part of #5530
Does this PR introduce a user-facing change?: